package cn.mdmm.common.spring.converter;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import cn.modoumama.common.utils.FileUtil;
import cn.modoumama.common.utils.StringUtils;

@Component
public class ObjectToStringConverter  implements Converter<Object,String>{

	@Override
	public String convert(Object source) {
		if(source != null){
			if(source instanceof MultipartFile){
				MultipartFile file = (MultipartFile) source;
				return FileUtil.saveFile(file);
			}else if(source instanceof StringBuffer){
				return StringUtils.filterJsAndAString(source.toString());
			}else{
				return StringUtils.filterLabelString(source.toString());
			}
		}
		return null;
	}

}
